﻿
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text.RegularExpressions;
using UnityEditor;
using UnityEngine;
using Util;
using Object = UnityEngine.Object;
namespace UtilEditors
{


#region 4.下拉框
[Serializable]
public enum ShowType {
    None = 0,
    IntType = 1,
    FloatType = 2,
    StrType = 3
}
#endregion

public class MyLayoutWindow : EditorWindow {

    [MenuItem("Tools/辅助/布局窗口")]
    static public void ShowWindow() {
        EditorWindow window = EditorWindow.GetWindow<MyLayoutWindow>();
        window.minSize = new Vector2(400, 450);
        //window.maxSize = new Vector2(800, 850);
        window.Show();
    }

    #region 1.坐标
    private Vector2 mVec2;
    private Vector3 mVec3;
    private Vector4 mVec4;
    #endregion

    #region 2.颜色
    private Color mColor;
    #endregion

    #region 3.滑块
    private float mSlider;
    #endregion

    #region 4.下拉框
    private int mPopupIndex, mLayer;
    private string[] mPopupStrArr = new[]{
            "第一",
            "第二",
            "第三"
        };
    private int[] mPopupIntArr = new[]{
            0,1,2
        };
    private string mTag;
    private ShowType mType;
    #endregion

    #region 6.勾选\折叠
    private bool mIsSelectTog, mIsFoldout, mIsTogGroup;
    private bool[] mIsGroupTogs = new bool[2] { false, false };
    #endregion

    #region 7.动画片段
    private AnimationCurve mCurve = new AnimationCurve();
    #endregion

    #region 8.对象选择框
    private Object mObj;
    private Texture mTexture;
    #endregion

    #region 9.路径选择
    private string mSelectPath = "";
    private string mDragSelect = "";
    #endregion

    float scrollBarValue1 = 1;
    float scrollValue1 = 1;
    int gridId = 1;
    int toolbarid = 1;
    string password = "";
    List<Object> SelectAll = new List<Object>();
    public void OnGUI() {



        #region 1.坐标
        EditorGUILayout.BeginHorizontal();
        this.mVec2 = EditorGUILayout.Vector2Field("二维坐标", this.mVec2, GUILayout.MaxWidth(150));
        this.mVec3 = EditorGUILayout.Vector3Field("三维坐标", this.mVec3, GUILayout.MaxWidth(250));
        EditorGUILayout.EndHorizontal();
        this.mVec4 = EditorGUILayout.Vector4Field("四维坐标", this.mVec4);
        #endregion

        #region 2.颜色
        this.mColor = EditorGUILayout.ColorField(this.mColor);
        #endregion

        #region 3.滑块
        GUILayout.BeginHorizontal();
        this.mSlider = EditorGUILayout.Slider(this.mSlider, 0, 10);

        scrollBarValue1 = GUILayout.HorizontalScrollbar(scrollBarValue1, 0, 0, 100, new[] { GUILayout.Width(100) });

        scrollValue1 = GUILayout.HorizontalSlider(scrollValue1, 0, 100);
        GUILayout.EndHorizontal();
        #endregion

        #region 4.下拉框
        EditorGUILayout.BeginHorizontal();
        this.mPopupIndex = EditorGUILayout.Popup(this.mPopupIndex, mPopupStrArr, GUILayout.MaxWidth(70));
        EditorGUILayout.LabelField(this.mPopupIndex.ToString(), GUILayout.MaxWidth(30));
        this.mPopupIndex = EditorGUILayout.IntPopup(this.mPopupIndex, mPopupStrArr, mPopupIntArr, GUILayout.MaxWidth(70));
        EditorGUILayout.LabelField(this.mPopupIndex.ToString(), GUILayout.MaxWidth(30));
        //自定义枚举下拉框
        this.mType = (ShowType)EditorGUILayout.EnumPopup(this.mType, GUILayout.MaxWidth(70));
        EditorGUILayout.LabelField(this.mType.ToString(), GUILayout.MaxWidth(70));
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();
        //Tag标签下拉框
        EditorGUILayout.LabelField("TagSelect:", GUILayout.MaxWidth(70));
        this.mTag = EditorGUILayout.TagField(this.mTag, GUILayout.MaxWidth(70));
        //Layer层下拉框
        EditorGUILayout.LabelField("LayerSelect:", GUILayout.MaxWidth(80));
        this.mLayer = EditorGUILayout.LayerField(this.mLayer, GUILayout.MaxWidth(70));
        EditorGUILayout.EndHorizontal();
        #endregion

        #region 5.提示框
        if (GUILayout.Button("点我")) {
            EditorUtility.DisplayDialog("标题", "提示内容", "确定", "取消");
        }
        #endregion

        #region 6.勾选\折叠
        this.mIsSelectTog = EditorGUILayout.Toggle("显示折叠", this.mIsSelectTog);
        if (this.mIsSelectTog) {
            this.mIsFoldout = EditorGUILayout.Foldout(this.mIsFoldout, "折叠");
            if (this.mIsFoldout) {
                this.mIsTogGroup = EditorGUILayout.BeginToggleGroup("选择：", this.mIsTogGroup);
                mIsGroupTogs[0] = EditorGUILayout.ToggleLeft("111", mIsGroupTogs[0]);
                mIsGroupTogs[1] = EditorGUILayout.ToggleLeft("222", mIsGroupTogs[1]);
                EditorGUILayout.EndToggleGroup();
            }
        }
        #endregion

        #region 7.动画片段
        this.mCurve = EditorGUILayout.CurveField("动画片段", this.mCurve);
        #endregion

        #region 8.对象选择框
        //type-Object
        this.mObj = EditorGUILayout.ObjectField("选择object", mObj, typeof(object), true) as Object;
        //type-Texture
        this.mTexture = EditorGUILayout.ObjectField("选择图片", this.mTexture, typeof(Texture), true) as Texture;
        #endregion

        #region 9.路径选择
        SelectFile(ref mSelectPath);

        //this.DragSelect("SelectAll", ref mDragSelect, ref SelectAll, ref mIsFoldout);
        #endregion

        #region 10.提示
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.HelpBox("oh my god!!!!!", MessageType.Error);
        EditorGUILayout.HelpBox("oh my god!!!!!", MessageType.Warning);
        EditorGUILayout.HelpBox("oh my god!!!!!", MessageType.Info);
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.HelpBox("oh my god!!!!!", MessageType.None);
        #endregion

        {
            GUILayout.BeginVertical();

            bool a = GUILayout.Button("一个Button");
            bool b = GUILayout.RepeatButton("RepeatButton");
            //RepeatButton 在按着的时候一直返回true，松开才返回false

            //选着列表
            {

                gridId = GUILayout.SelectionGrid(gridId, new[] { "1", "2", "3", "4", "5", "6" }, 4);//一行4个

                toolbarid = GUILayout.Toolbar(toolbarid, new[] { "1", "2", "3" });
            }

            //输入框
            {
                GUILayout.TextField("TextField只能一行");
                GUILayout.TextArea("TextArea可以多行\n 第二行");

                //密码

                password = GUILayout.PasswordField(password, '*');

            }
            //布局
            {
                //保证块里写的控件只在Area规定的范围内,这里设置放到右下角
                {
                    GUILayout.BeginArea(new Rect(position.width - 250, position.height - 150, 250, 150));
                    //...
                    GUILayout.EndArea();
                }

                {
                    GUILayout.BeginHorizontal();
                    //...水平布局
                    GUILayout.EndHorizontal();
                }

                {
                    GUILayout.BeginVertical();
                    //...垂直布局
                    GUILayout.EndVertical();
                }
            }
            GUILayout.EndVertical();
        }
    }
    public void SelectFile(ref string Path) {
        if (GUILayout.Button("选择文件路径", GUILayout.MaxWidth(80))) {
            Path = EditorUtility.OpenFilePanel("选择文件", "", "");
        }
        Path = EditorGUILayout.TextField(Path, GUILayout.MaxHeight(20));
    }


    /// <image url= "D:\_Project\Unity\My\monobot20\MONOBOTS\Assets\Plugins\Library\myTool\Editor\0651800.png" scale="0.01" />
}

public static class EditorWindowModel {


    }
}